import { InputQuestion, QuestionBase, SelectQuestion, TextQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { regExp } from '@/utils/regExp';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'code',
        label: '编码',
        value: null
      }),
      new InputQuestion({
        key: 'name',
        label: '名称',
        value: null
      }),
      new SelectQuestion({
        key: 'status',
        label: '档案准入',
        value: null,
        options: [
          {
            label: '开',
            value: 1
          },
          {
            label: '关',
            value: 0
          }
        ]
      })
    ];
    return questions;
  }
  getAddQuestions(showType) {
    const questions: QuestionBase<any>[] = [
      showType == 'ADD'
        ? new InputQuestion({
            key: 'code',
            label: '编码',
            required: true,
            prompt: '请输入不超过20个字符的有效字母或数字组合，不能为空。',
            value: null,
            placeholder: '请输入',
            reg: regExp.alphanumer
          })
        : new TextQuestion({
            key: 'code',
            label: '编码',
            value: null
          }),
      new InputQuestion({
        key: 'name',
        label: '名称',
        required: true,
        prompt: '名称不可为空，至多允许输入20个字符',
        value: null,
        placeholder: '请输入',
        reg: regExp.len020
      }),
      new TextQuestion({
        key: 'parentId',
        value: null,
        hide: true
      }),
      new TextQuestion({
        key: 'id',
        value: null,
        hide: true
      })
    ];
    return questions;
  }
  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'code',
        value: '编码'
      }),
      new TextTable({
        key: 'name',
        value: '名称'
      }),

      new TextTable({
        key: 'status',
        value: '档案准入',
        type: 'slot',
        state: {
          slotName: 'stateSwitch'
        }
      }),
      new TextTable({
        key: 'creatorName',
        value: '创建人'
      }),
      new TextTable({
        key: 'createdTime',
        value: '创建时间'
      }),
      new TextTable({
        key: 'modifierName',
        value: '修改人'
      }),
      new TextTable({
        key: 'modifiedTime',
        value: '修改时间'
      })
    ];
    return tables;
  }
}

export default new HomeService();
